package com.wizards.mtg;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.wizards.mtg.card.KeywordAbility;
import com.wizards.mtg.card.Subtype;
import com.wizards.mtg.card.Supertype;
import com.wizards.mtg.card.Type;
import com.wizards.mtg.util.Util;

public abstract class Card
{	
	protected String name;		
	protected Set<Supertype> supertypes;
	protected Set<Type> types;
	protected Set<Subtype> subtypes;
	protected List<Payable> manaCost;
	protected Set<KeywordAbility> keywordAbilities;
	protected int power;
	protected int toughness;
	protected Player owner;
	protected Player controller;

	public Card(String name, Type type) {
		this(name, null, Util.toSet(type), null);
	}
	
	public Card(String name, Type type, Subtype... subtypes) {
		this(name, null, Util.toSet(type), Util.toSet(subtypes));
	}
	
	public Card(String name, Supertype supertype, Type type, Subtype... subtypes) {
		this(name, Util.toSet(supertype), Util.toSet(type), Util.toSet(subtypes));
	}

	public Card(String name, Set<Supertype> supertypes, Set<Type> types,Set<Subtype> subtypes) {
		this.name = name;
		this.supertypes = supertypes;
		this.types = types;
		this.subtypes = subtypes;
		this.manaCost = new ArrayList<Payable>();
		this.keywordAbilities = new HashSet<KeywordAbility>();
		this.power = 0;
		this.toughness = 0;
		this.owner = null;
		this.controller = null;
	}

	public String getName()                                  { return name; }
	
	public Set<Supertype> getSupertypes()                    { return supertypes; }
	public void setSupertypes(Supertype... supertypes)       { this.supertypes = Util.toSet(supertypes); }
	public void addSupertypes(Supertype... supertypes)       { this.supertypes.addAll(Util.toSet(supertypes)); }
	public void removeSupertypes(Supertype... supertypes)    { this.supertypes.removeAll(Util.toSet(supertypes)); }

	public Set<Type> getTypes()                              { return types; }
	public void setTypes(Type... types)                      { this.types = Util.toSet(types); }
	public void addTypes(Type... types)                      { this.types.addAll(Util.toSet(types)); }
	public void removeTypes(Type... types)                   { this.types.removeAll(Util.toSet(types)); }

	public Set<Subtype> getSubtypes()                        { return subtypes; }
	public void setSubtypes(Subtype... subtypes)             { this.subtypes = Util.toSet(subtypes); }
	public void addSubtypes(Subtype... subtypes)             { this.subtypes.addAll(Util.toSet(subtypes)); }
	public void removeSubtypes(Subtype... subtypes)          { this.subtypes.removeAll(Util.toSet(subtypes)); }

	public List<Payable> getManaCost()                       { return manaCost; }
	public void setManaCost(Payable... mana)             	 { this.manaCost = Util.toList(mana); }	

	public Set<KeywordAbility> getKeywordAbilities()         { return keywordAbilities; }
	public void setKeywordAbilities(KeywordAbility... ka)    { this.keywordAbilities = Util.toSet(ka); }	
	public void addKeywordAbilities(KeywordAbility... ka)    { this.keywordAbilities.addAll(Util.toSet(ka)); }
	public void removeKeywordAbilities(KeywordAbility... ka) { this.keywordAbilities.removeAll(Util.toSet(ka)); }
	
	public int getPower()                                    { return power; }
	public int getToughness()                                { return toughness; }
	public void setPower(int power)                          { this.power = power; }
	public void setToughness(int toughness)                  { this.toughness = toughness; }

	public Player getOwner()                                 { return owner; }		
	public Player getController()                            { return (controller == null) ? owner : controller; }
	public void setOwner(Player player)                      { if (owner == null) this.owner = player; }
	public void setController(Player player)                 { this.controller = player; }
}
